package com.skytech.component.monitor.data;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface PM25DataDAO extends JpaRepository<PM25Data,String> {

    @Query(value="select * from pm_data group by monitor_point HAVING area=:area",nativeQuery = true)
    List<PM25Data> findByGroupByMonitorPoint(@Param("area") String area);


    @Query(value = "select * from pm_data where monitor_point=:monitorPoint and area=:area ORDER BY crawling_time DESC LIMIT 1",nativeQuery = true)
    PM25Data findByMonitorPointOrderByCrawlingTime(@Param("area") String area,@Param("monitorPoint") String monitorPoint);

    @Query(value="select p.* from pm_data p where p.monitor_point is null and area=:area  ORDER BY crawling_time desc LIMIT 1",nativeQuery = true)
    PM25Data findByAreaOrderByCrawlingTime(@Param("area") String area);
}
